package com.example.library.http;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by dadong on 2018/8/17.
 * Describe:
 * http://172.16.41.235:2048/api/ZXYYTS/W_ZXYYTS_GetCourseware?levelCode=B&knowledge=hello
 */
public class Api {

    //    public static String baseUrl = "http://60.190.136.238:2048/api/";
    public static ApiService apiService;


    public static ApiService getApiService() {
        if (apiService == null) {
            synchronized (Api.class) {
                if (apiService == null) {
                    new Api();
                }
            }
        }
        return apiService;
    }

    private static final OkHttpClient client = new OkHttpClient.Builder().
            connectTimeout(60, TimeUnit.SECONDS).
            readTimeout(60, TimeUnit.SECONDS).
            writeTimeout(60, TimeUnit.SECONDS).build();

    private Api() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(KnowledgeParseBaseUrl.getBaseUrl())
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        apiService = retrofit.create(ApiService.class);
    }
}
